package com.inviscidlabs.schooled;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;

public class FragmentClassEdit extends Fragment{
	
	
//Variables
	private EditText fieldClassName;
	private EditText fieldEmail;
	private GradeDB dB;
	
	
//==============ON CREATE VIEW==============
	
	 @Override
	 public View onCreateView(LayoutInflater inflater, ViewGroup container,
	      Bundle savedInstanceState) {
		 View v = inflater.inflate(R.layout.screen_classedit, container);
		 fieldClassName=(EditText) v.findViewById(R.id.field_ce_className);
		 fieldEmail = (EditText)v.findViewById(R.id.field_ce_classEmail);
		 return v;	 
	 }
	 
	 
//===================ON ATTACH===================
	 @Override
	  public void onAttach(Activity activity) {
	    super.onAttach(activity);
	    dB=GradeDB.getInstance(activity);
	 }
	 
//=============CREATE CLASS===============
	 
	 public void createClass(long sId){
		 String classNameText= fieldClassName.getText().toString();
		 if(classNameText.matches("")){
			 //TODO Dialog or toast
			 Toast.makeText(getActivity(), "Put something in douche", Toast.LENGTH_LONG).show();
		 } else{
			 dB.createClass(classNameText, sId, fieldEmail.getText().toString());
		 }
		 
	 }
	 
//=============Edit Class==================
	 public void editClass(long cId){
		 String classNameText= fieldClassName.getText().toString();
		 if(classNameText.matches("")){
			 //TODO Dialog or toast
		 } else {
			 dB.editClass(classNameText, fieldEmail.getText().toString(), cId);
		 }
	 }
	 
	 
//===============Delete Class==================
	 public void deleteClass(long cId){
		 dB.deleteClass(cId);
	 }
	 
//============Clear Fields============
	 public void clearFields(){
		fieldClassName.setText("");
		fieldEmail.setText("");
	 }
	

}
